1 module common_macos; 2 import commons; 3 enum XCodeDFolder = "D"; 4 5 void setupPerCompiler(ref Terminal t, string compiler, string arch, out string extraLinkerFlags) 6 { 7 switch(compiler) 8 { 9 default: 10 case "auto", "ldc2": 11 { 12 string outputDruntime = getHipPath("build", "appleos", XCodeDFolder, "static", "libdruntime-ldc.a"); 13 string ldcLibPath = buildNormalizedPath(configs["ldcPath"].str, "lib-"~arch); 14 string druntimeLib = ldcLibPath.getFirstExisting("libdruntime-ldc.a"); 15 if(druntimeLib == null) 16 throw new Error("DRuntime Library not found on path "~configs["ldcPath"].str); 17 t.writelnSuccess("Copying druntime to XCode ", druntimeLib, " -> ", outputDruntime); 18 t.flush; 19 std.file.copy(druntimeLib, outputDruntime); 20 21 string phobosLib = ldcLibPath.getFirstExisting("libphobos2.a", "libphobos.a", "libphobos2-ldc.a"); 22 if(phobosLib == null) throw new Error("Could not find your phobos library"); 23 string outputPhobos = getHipPath("build", "appleos", XCodeDFolder,"static"); 24 std.file.mkdirRecurse(outputPhobos); 25 outputPhobos = buildNormalizedPath(outputPhobos, "libphobos2.a"); 26 t.writelnSuccess("Copying phobos to XCode ", phobosLib, "->", outputPhobos); 27 t.flush; 28 std.file.copy(phobosLib, outputPhobos); 29 30 extraLinkerFlags = "-ldruntime-ldc "; 31 break; 32 } 33 case "dmd": 34 { 35 string outputDruntime = getHipPath("build", "appleos", XCodeDFolder, "static", "libdruntime-ldc.a"); 36 if(std.file.exists(outputDruntime)) std.file.remove(outputDruntime); 37 38 string phobosLib = configs["phobosLibPath"].str.getFirstExisting("libphobos2.a", "libphobos.a", "libphobos2-ldc.a"); 39 if(phobosLib == null) throw new Error("Could not find your phobos library"); 40 41 string outputPhobos = getHipPath("build", "appleos", XCodeDFolder,"static"); 42 std.file.mkdirRecurse(outputPhobos); 43 outputPhobos = buildNormalizedPath(outputPhobos, "libphobos2.a"); 44 t.writelnSuccess("Copying phobos to XCode ", phobosLib, "->", outputPhobos); 45 t.flush; 46 std.file.copy(phobosLib, outputPhobos); 47 } 48 } 49 } 50 51 52 void prepareAppleOSBase(Choice* c, ref Terminal t, ref RealTimeConsoleInput input) 53 { 54 cached(() => timed(() => loadSubmodules(t, input))); 55 putResourcesIn(t, getHipPath("build", "appleos", "assets")); 56 runEngineDScript(t, "releasegame.d", configs["gamePath"].str); 57 //The template may not be present 58 cached(() => timed(() => outputTemplate(t, configs["gamePath"].str))); 59 } 60 61 void cleanAppleOSLibFolder() 62 { 63 string targetDir = getHipPath("build", "appleos", XCodeDFolder, "libs"); 64 if(std.file.exists(targetDir)) 65 std.file.rmdirRecurse(targetDir); 66 std.file.mkdirRecurse(targetDir); 67 } 68 69 void injectLinkerFlagsOnXcode(ref Terminal t, ref RealTimeConsoleInput input, string extraLinkerFlags) 70 { 71 string[] gemsToInstall = ["xcodeproj", "json"]; 72 static void installGem(ref Terminal t, ref RealTimeConsoleInput input, string gem) 73 { 74 if(executeShell("gem list | grep "~gem).status) 75 { 76 if(!pollForExecutionPermission(t, input ,"Ruby `gem` called '"~gem~"' is not installed, attempt to install?")) 77 throw new Error("Can't update HipremeEngine.xcodeproj without installing dependency for ruby script."); 78 wait(spawnShell("sudo gem install "~gem)); 79 } 80 } 81 with(WorkingDir(getHipPath("build", "appleos"))) 82 { 83 foreach(gem; gemsToInstall) 84 installGem(t, input, gem); 85 spawnShell("ruby injectLib.rb "~extraLinkerFlags); 86 } 87 } 88 89 90 private __gshared string codeSignUuid; 91 /** 92 * No need to codesign a non release version. 93 */ 94 string getCodeSignCommand(ref Terminal t, bool isReleaseVersion = false) 95 { 96 if(isReleaseVersion) 97 { 98 cached( 99 { 100 auto res = executeShell("security find-identity -v -p codesigning"); 101 if(res.status) 102 throw new Error("Could not get codesigning UUID for building to iOS"); 103 import std.string:indexOf, chomp; 104 string uuid = res.output; 105 codeSignUuid = uuid[uuid.indexOf(')')+1..uuid.indexOf('"')].chomp; 106 t.writelnHighlighted("CodeSign UUID: ", codeSignUuid); 107 }); 108 return "PROVISIONING_PROFILE='"~codeSignUuid~"' "; 109 } 110 else 111 return "CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO CODE_SIGN_ALLOWED=NO"; 112 } 113